<?php
import('miho.event.*');
/**
* Controller
*/
class Controller extends EventDispatcher
{
  protected static $_instance;
  public static function getInstance(){
    if(self::$_instance==null){
      self::$_instance= new Controller();
    }
    return self::$_instance;
  }
    
  protected $_actionStack = array();
  protected $_application = 'default';
  public function getApplication(){
    return $this->_application;
  }
  public function setApplication($value){
    var_dump($value);
  	$this->_application = $value;
  }
  
  protected $_controllersPath = null;
  
  protected function __construct()
  {
    
  }
  
  
  public function forward($controller,$action){
    
  }
  
  public function executeAction($controller, $action){
    $controller = $this->getController($controller);
    return $controller->execute($action);
  }
  
  public function getController($controller){
  	$controllerName = $controller;
    $controller = ucfirst($controller).'Controller';
    
    import($this->getControllersPath().'.'.$controller);
    $controller = new $controller();
    $controller->setName($controllerName);
    
    return $controller;
  }
  
  public function getControllersPath(){
    if($this->_controllersPath==null){
      $this->_controllersPath = $this->_application.'.controller';
    }
    return $this->_controllersPath;
  }
}